import os
import sys
import re
import time
import shutil
from flask import Flask, render_template, send_from_directory, flash, request, redirect, session, abort
from unicodedata import normalize
import sqlite3 as sql
#获取文件大小
def Get_Size(fpath):
    fsize = os.path.getsize(fpath)
    fsize = fsize/float(1024)
    return round(fsize,2)

#获取文件修改时间
def Time_localtime(timestamp):
    stime = time.localtime(timestamp)
    return time.strftime('%Y-%m-%d %H:%M:%S',stime)
def Get_ModifyTime(fpath):
    t = os.path.getmtime(fpath)
    return Time_localtime(t)

#获取路径下所有目录及文件
def dir_list(path):
    fileList = []
    dirList = []
    for x in os.listdir(path):
        if os.path.isfile(os.path.join(path, x)):
            fsize = Get_Size(os.path.join(path, x))
            ftime = Get_ModifyTime(os.path.join(path, x))
            fileList.append({"name":x,"size":fsize,"date":ftime})
        else:
            dtime = Get_ModifyTime(os.path.join(path, x))
            dirList.append({"name":x,"date":dtime})

    return fileList, dirList



